package com.wanmait.movies.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wanmait.movies.util.DBHelper;
import com.wanmait.movies.vo.Maneger;

public class ManegerDao {

	private ManegerDao() {}
	private static ManegerDao manegerDao = new ManegerDao();
	public static ManegerDao getDao() {
		return manegerDao;
	}
	
	//判断登录管理员账户对错
	public Maneger logManeger(Maneger m) {
		Connection co = DBHelper.getDBHelper().getconn();
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		String sql="select * from Maneger where maneger_name=? and maneger_password=?";
		try {
			ps=co.prepareStatement(sql);
			ps.setString(1, m.getManegerName());
			ps.setString(2, m.getManegerPassword());
			
			rs=ps.executeQuery();
			
			if(rs.next()) {
				Maneger maneger =new Maneger();
				maneger.setId(rs.getInt("id"));
				maneger.setManegerName(rs.getString("maneger_name"));
				maneger.setManegerPassword(rs.getString("maneger_password"));
				
				return maneger;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			DBHelper.getDBHelper().close(rs, ps, co);
		}
		return null;
	}
	
}
